<?php
/**
 * 作者：亿泽
 * QQ：1260435972
 * 交流群：557649112
 * 日期：2022/03/31
 * 项目名称：亿泽不用验证系统
 * 项目说明：请勿进行违法用途，当您在使用本项目中的任何源代码时默认同意作者的观点！
 * 观点：
 * 1.禁止将本系统使用于违法违规用途。
 * 2.禁止将本系统使用包含但不限于 灰色产业/进行灰色产业的机器人插件/框架。
 * 3.禁止进行商业性质的二创二开，仅授权免费个人使用
 * 4.本系统为免费/全开源项目，禁止进行任何商业活动 除非 获得作者授权！
 * 感谢：
 * 1.使用了 光年 后台模板
 * 2.参考了 网络上部分代码资料
 * 3.感谢各位的使用~
 **/
require_once "../../include/common.php";


if (isset($_POST['mode'])!="" && isset($_POST['appid'])!="") {
    $mode = daddslashes ($_POST['mode']);
    $appid = daddslashes ($_POST['appid']);
    $appver = daddslashes ($_POST['appver']);
    //获取 现行时间戳
    $time = time ();
    $time = $time - $interval;

    switch ($mode) {
        case 0:
            $result = Db::table (online) ->find ("trait","appid = '$appid' and times >='$time'")-> fetchAll ();
            $rowCount = count ($result);
            $json = json_encode (array (
                "code" => 200 ,
                "msg"=>"应用近'$interval'秒在线人数",
                "num" => $rowCount ,
                "status" => true
            ) , JSON_UNESCAPED_UNICODE);
            echo ($json);
            break;
        case 1:
            if (isset($appver)!="") {
                $result = Db::table (online) ->find ("trait","appid = '$appid' and appver='$appver' and times >='$time'")-> fetchAll ();
                $rowCount = count ($result);
                $json = json_encode (array (
                    "code" => 200 ,
                    "msg"=>"该版本近'$interval'秒在线人数",
                    "num" => $rowCount ,
                    "status" => true
                ) , JSON_UNESCAPED_UNICODE);
                echo ($json);
            } else {
                $json = json_encode (array (
                    "code" => 202 ,
                    "msg" => "当mod=1 or 3时 appver 不可省略或为空！" ,
                    "status" => false
                ) , JSON_UNESCAPED_UNICODE);
                echo ($json);
            }
            break;
        case 2:
            $result = Db::table (online) ->find ("trait","appid = '$appid'")-> fetchAll ();
            $rowCount = count ($result);
            $json = json_encode (array (
                "code" => 200 ,
                "msg"=>"应用使用过的总人数",
                "num" => $rowCount ,
                "status" => true
            ) , JSON_UNESCAPED_UNICODE);
            echo ($json);
            break;
        case 3:
            if (isset($appver)!="") {
                $result = Db::table (online) ->find ("trait","appid = '$appid' and appver='$appver'")-> fetchAll ();
                $rowCount = count ($result);
                $json = json_encode (array (
                    "code" => 200 ,
                    "msg"=>"该版本近使用过的人数",
                    "num" => $rowCount ,
                    "status" => true
                ) , JSON_UNESCAPED_UNICODE);
                echo ($json);
            } else {
                $json = json_encode (array (
                    "code" => 202 ,
                    "msg" => "当mod=1 or 3时 appver 不可省略或为空！" ,
                    "status" => false
                ) , JSON_UNESCAPED_UNICODE);
                echo ($json);
            }
            break;
        default:
            $json = json_encode (array (
                "code" => 202 ,
                "msg" => "没有该mode值" ,
                "status" => false
            ) , JSON_UNESCAPED_UNICODE);
            echo ($json);
    }
}else{
    $json = json_encode (array (
        "code" => 202 ,
        "msg" => "参数错误!!" ,
        "status" => false
    ) , JSON_UNESCAPED_UNICODE);
    echo ($json);
}


